package com.example.market3w;

import java.util.ArrayList;
import java.util.HashMap;

import android.app.Activity;
import android.content.res.Resources;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.SimpleAdapter;

/**
 * A simple {@link android.support.v4.app.Fragment} subclass. Activities that
 * contain this fragment must implement the
 * {@link TelechargementFragment.OnFragmentInteractionListener} interface to
 * handle interaction events. Use the {@link TelechargementFragment#newInstance}
 * factory method to create an instance of this fragment.
 * 
 */
public class TelechargementFragment extends Fragment implements OnFragmentInteractionListener {
	// TODO: Rename parameter arguments, choose names that match
	// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
	private static final String ARG_PARAM1 = "param1";
	private static final String ARG_PARAM2 = "param2";

	// TODO: Rename and change types of parameters
	private String mParam1;
	private String mParam2;

	private OnFragmentInteractionListener mListener;
	private ListView menuElementsList ;

	/**
	 * Use this factory method to create a new instance of this fragment using
	 * the provided parameters.
	 * 
	 * @param param1
	 *            Parameter 1.
	 * @param param2
	 *            Parameter 2.
	 * @return A new instance of fragment TelechargementFragment.
	 */
	// TODO: Rename and change types and number of parameters
	public static TelechargementFragment newInstance(String param1,
			String param2) {
		TelechargementFragment fragment = new TelechargementFragment();
		Bundle args = new Bundle();
		args.putString(ARG_PARAM1, param1);
		args.putString(ARG_PARAM2, param2);
		fragment.setArguments(args);
		return fragment;
	}

	public TelechargementFragment() {
		// Required empty public constructor
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		if (getArguments() != null) {
			mParam1 = getArguments().getString(ARG_PARAM1);
			mParam2 = getArguments().getString(ARG_PARAM2);
		}
		
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// Inflate the layout for this fragment
		View view = inflater.inflate(R.layout.fragment_telechargement, container,
				false);
		menuElementsList = (ListView)view.findViewById(R.id.list_telechargement);
		remplirMenu();
		return view;
	}

	// TODO: Rename method, update argument and hook method into UI event
	public void onButtonPressed(Uri uri) {
		if (mListener != null) {
			mListener.onFragmentInteraction(uri);
		}
	}

	@Override
	public void onAttach(Activity activity) {
		super.onAttach(activity);
		try {
			mListener = (OnFragmentInteractionListener) activity;
		} catch (ClassCastException e) {
			throw new ClassCastException(activity.toString()
					+ " must implement OnFragmentInteractionListener");
		}
	}

	@Override
	public void onDetach() {
		super.onDetach();
		mListener = null;
	}

	public void remplirMenu(){
		ArrayList<HashMap<String, String>> listItem ;
		HashMap<String, String> contenu ;
		SimpleAdapter adapter;
		Resources res = getResources();
		listItem = new ArrayList<HashMap<String,String>>();
		
		contenu = new HashMap<String, String>();
		contenu.put("nom","fichier html/php");
		contenu.put("description","ceci est un fichier internet");
		contenu.put("image", Integer.toString(R.drawable.internet_document));
		contenu.put("taille", "321 Ko");
		listItem.add(contenu);
		
		contenu = new HashMap<String, String>();
		contenu.put("nom","fichier video");
		contenu.put("description","ceci est un fichier video");
		contenu.put("image", Integer.toString(R.drawable.video_file));
		contenu.put("taille", "243 Mo");
		listItem.add(contenu);
		
		contenu = new HashMap<String, String>();
		contenu.put("nom","fichier texte");
		contenu.put("description","ceci est un fichier texte");
		contenu.put("image", Integer.toString(R.drawable.text_file));
		contenu.put("taille", "2,2 Mo");
		listItem.add(contenu);
		
		contenu = new HashMap<String, String>();
		contenu.put("nom","fichier xls");
		contenu.put("description","ceci est un fichier xls");
		contenu.put("image", Integer.toString(R.drawable.xls_file));
		contenu.put("taille", "80 Ko");
		listItem.add(contenu);
		
		contenu = new HashMap<String, String>();
		contenu.put("nom","fichier zip");
		contenu.put("description","ceci est un fichier zip");
		contenu.put("image", Integer.toString(R.drawable.zip_file));
		contenu.put("taille", "120 Ko");
		listItem.add(contenu);
		
		contenu = new HashMap<String, String>();
		contenu.put("nom","fichier image");
		contenu.put("description","ceci est un fichier image");
		contenu.put("image", Integer.toString(R.drawable.image_file));
		contenu.put("taille", "4 Mo");
		listItem.add(contenu);
		
		contenu = new HashMap<String, String>();
		contenu.put("nom","fichier power point");
		contenu.put("description","ceci est un fichier power point");
		contenu.put("image", Integer.toString(R.drawable.ppt_file));
		contenu.put("taille", "541 Ko");
		listItem.add(contenu);
		
		contenu = new HashMap<String, String>();
		contenu.put("nom","fichier pdf");
		contenu.put("description","ceci est un fichier pdf");
		contenu.put("image", Integer.toString(R.drawable.pdf));
		contenu.put("taille", "154 Ko");
		listItem.add(contenu);
		
		adapter = new SimpleAdapter(getActivity().getBaseContext(), listItem, R.layout.telechargement_item, new String[]{"nom","description","image","taille"}, new int[]{R.id.nomFichier,R.id.descriptionFichier,R.id.imageTypeFichier,R.id.taille});
		
		menuElementsList.setAdapter(adapter);
	}

	@Override
	public void onFragmentInteraction(Uri uri) {
		// TODO Auto-generated method stub
		
	}

}
